package com.foreveross.framework.example.tags.controller;

import com.foreveross.framework.example.tags.domain.City;
import com.foreveross.framework.example.tags.domain.Customer;
import com.foreveross.framework.example.tags.domain.Hobby;
import com.foreveross.framework.example.tags.service.CityService;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class CheckboxesController {

  @Autowired
  private CityService cityService;

  @RequestMapping(value = "/example/checkboxes", method = RequestMethod.GET)
  public String execute(ModelMap modelMap) {
    Customer customer = new Customer();
    customer.setCities(Lists.newArrayList(
        new City("广州", "gz"), new City("珠海", "zh")));
    customer.setHobbies(Lists.newArrayList(Hobby.RUNNING, Hobby.BASKETBALL));

    modelMap.addAttribute("customer", customer);
    modelMap.addAttribute("cities", cityService.findCities());
    modelMap.addAttribute("hobbies", Lists.newArrayList(
        Hobby.BADMINTON, Hobby.RUNNING, Hobby.BASKETBALL, Hobby.FOOTBALL));

    return "example/checkboxes";
  }

}
